<template>
  <div class="teacherCourseInfo">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程设计</el-breadcrumb-item>
      <el-breadcrumb-item>查看课程（课设需求）</el-breadcrumb-item>
    </el-breadcrumb>
    <el-row :gutter="20" class="mb-12">
      <el-col :span="5">
        <div class="">
          <el-select v-model="form.majorID" placeholder="请选择专业" class="max-width">
            <el-option
              v-for="item in major"
              :label="item.majorName"
              :value="item.majorID">
            </el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            v-model="form.grade"
            align="right"
            type="year"
            class="max-width"
            placeholder="请选择年级"
            @change="getGrade">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-date-picker
            v-model="form.academicYear"
            align="right"
            type="year"
            class="max-width"
            placeholder="请选择学年"
            @change="getAcademicYear">
          </el-date-picker>
        </div>
      </el-col>
      <el-col :span="5">
        <div class="">
          <el-select v-model="form.term" placeholder="请选择学期">
            <el-option label="01" value="01"></el-option>
            <el-option label="02" value="02"></el-option>
          </el-select>
        </div>
      </el-col>
      <el-col :span="4">
        <div class="overflow-clear">
          <el-button type="primary" class="add-pd-26 float-right" @click="searchCourse">搜索</el-button>
        </div>
      </el-col>
    </el-row>
    <el-table
      :data="courseInfo"
      style="width: 100%">
      <el-table-column
        prop="courseNameCN"
        label="课程名称"
        min-width="140">
      </el-table-column>
      <el-table-column
        prop="teacherName"
        label="任课教师"
        min-width="130">
      </el-table-column>
      <el-table-column
        prop="majorName"
        label="专业"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="className"
        label="班级"
        min-width="130">
      </el-table-column> 
      <el-table-column
        prop="term"
        label="学期"
        min-width="80">
      </el-table-column>
      <el-table-column
        prop="academicYear"
        label="学年"
        min-width="100">
      </el-table-column>
      <el-table-column
        prop="grade"
        label="年级"
        min-width="80">
      </el-table-column>
      <el-table-column
        prop="startTime"
        label="开始时间"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="endTime"
        label="结束时间"
        min-width="120">
      </el-table-column>
      <el-table-column
        prop="courseArrangeInfo"
        label="课设安排"
        min-width="120">
        <template scope="scope">
          <span v-if="scope.row.isfinish==='已安排'">已安排</span>
          <el-button v-else @click.native.prevent="newCourseDesign(scope.row.trainingCourseID,scope.row.classID)" type="text">未安排
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="paging">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="pageSizes"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalPage">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'uploadCourseDesign',
    data() {
      return {
        form: {
          majorID: '',
          grade: '',
          academicYear: '',
          term: '',
        },
        courseInfo: [{
          courseNameCN: '数据库基础教程',
          className: '软件132003班',
          startTime: '2016-03-01',
          endTime: '2016-03-15',
          majorName: '软件工程',
          grade: '2013',
          academicYear: '2016',
          term: '1',
          isfinish: '已安排',
          //隐藏
          trainingCourseID: '',
          classID: '',

        },
          {
            courseNameCN: '算法与数据结构',
            className: '软件132003班',
            startTime: '2017-03-01',
            endTime: '2017-03-15',
            majorName: '软件工程',
            grade: '2013',
            academicYear: '2017',
            term: '1',
            isfinish: '未安排'
          }],
        major: [],
        totalPage: 20,
        currentPage: 1,
        pageSizes: [10, 20, 30, 40],
        pageSize: 10,
        searchStatus: 0,
      }
    },
    created () {
      this.res();
      this.getMajor();
    },
    methods: {
      res: function () {
        this.$http.get(`${this.$until.url}/courseDesign/getCourseDesign`,
          {//请求参数
            params: {
              page: this.currentPage,
              pageSize: this.pageSize
            }
          })
          .then((res) => {
            this.courseInfo = res.body.course
            this.totalPage = res.body.num.num
            console.log(res)
          }, (err) => {
            console.log('服务器异常')
          })
      },
      getMajor(){
        this.$http.get(`${this.$until.url}/courseDesign/getMajorDesign`)
          .then((res) => {
            //console.log(res)
            this.major = res.body
          }, (err) => {
            // 响应错误回调
            //console.log(err)
          })
      },
      handleSizeChange(val) {
        //console.log(`每页 ${val} 条`);
        this.pageSize = val
        if (this.searchStatus == 1) {
          this.searchCourse()
        } else {
          this.res()
        }
      },
      handleCurrentChange(val) {
        //console.log(`当前页: ${val}`);
        this.currentPage = val;
        if (this.searchStatus == 1) {
          this.searchCourse()
        } else {
          this.res()
        }
      },
      getGrade(val){
        this.form.grade = val
      },
      getAcademicYear(val){
        this.form.academicYear = val
      },
      searchCourse() {
        this.searchStatus = 1
        this.$http.post(`${this.$until.url}/courseDesign/getCourseDesign`, this.form,
          {//请求参数
            params: {
              page: this.currentPage,
              pageSize: this.pageSize
            },
            emulateJSON: true
          })
          .then((res) => {
            //console.log(res)
            this.courseInfo = res.body.course
            this.totalPage = res.body.num.num
          }, (err) => {
            // 响应错误回调
            console.log('服务器异常')
          })
      },
      newCourseDesign(trainingCourseID,classID){
      	
        this.$router.push({path: 'NewCourseDesign', 
        	query: {trainingCourseID: trainingCourseID,classID: classID}})
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
